package com.usian.user.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//代码创建 mq


@Configuration
public class RabbitmqConfig {
    // 交换机名称
    public static final String EXCHANGE_DIRECT_AUTHAUTO = "exchange_direct_authauto";

    // 队列名称1
    public static final String QUEUE_AUTHAUTO_USER = "queue_authauto_user";

    // 队列名称2
    public static final String QUEUE_AUTHAUTO_ADMIN = "queue_authauto_admin";

    public static final String ROUTINGKEY = "authautouser";

    // 声明交换机
    @Bean(EXCHANGE_DIRECT_AUTHAUTO)
    public Exchange EXCHANGE_DIRECT_AUTHAUTO(){
        return ExchangeBuilder.directExchange(EXCHANGE_DIRECT_AUTHAUTO).durable(true).build();
    }
    // 声明队列
    @Bean(QUEUE_AUTHAUTO_USER)
    public Queue QUEUE_AUTHAUTO_USER(){
        Queue queue = new Queue(QUEUE_AUTHAUTO_USER);
        return queue;
    }

    @Bean(QUEUE_AUTHAUTO_ADMIN)
    public Queue QUEUE_AUTHAUTO_ADMIN(){
        Queue queue = new Queue(QUEUE_AUTHAUTO_ADMIN);
        return queue;
    }

    // 绑定交换机和队列
    @Bean("bind1")
    public Binding EXCHANGE_DIRECT_AUTHAUTO_USER(@Qualifier(EXCHANGE_DIRECT_AUTHAUTO) Exchange exchange,
                                                 @Qualifier(QUEUE_AUTHAUTO_USER) Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY ).noargs();
    }

    @Bean("bind2")
    public Binding EXCHANGE_DIRECT_AUTHAUTO_ADMIN(@Qualifier(EXCHANGE_DIRECT_AUTHAUTO) Exchange exchange,
                                                  @Qualifier(QUEUE_AUTHAUTO_ADMIN) Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("authautoadmin").noargs();
    }



}
